module TerminalKeynote
  class Slide
    attr_accessor :blocks, :vertical_align

    DEFAULT_VERTICAL_ALIGN = :center

    def initialize(options={})
      @blocks =
        if options[:content]
          [Block.new(content: options[:content])]
        else
          options[:blocks]
        end
      @blocks ||= []
      @vertical_align = options[:vertical_align] || DEFAULT_VERTICAL_ALIGN
    end

    def height
      blocks.map(&:lines).flatten.count
    end

    def top_margin
      case vertical_align
      when :top
        margin = 0
      when :center
        margin = (Window.height - height) / 2
      when :bottom
        margin = Window.height - height
      end
    end

    def ==(other)
      blocks == other.blocks
    end
  end
end
